// 3.1 新建action/channel.js文件

import request from '../../utils/request';
import { CHANNEL_GET_LIST, CHANNEL_SET_INDEX } from './actionTypes';
/** 更新activeIndex的action */
// 3.2 声明getChannelCreator的创建函数
export function getChannelCreator() {
  // 🔑 返回一个异步函数，使用形参的dispatch
  return async (dispatch) => {
    const res = await request.get('/v1_0/channels');
    // 5.2 使用常量替换字符串
    dispatch({ type: CHANNEL_GET_LIST, payload: res.data.channels });
  };
}

// 4.2 reducer中定义type:setActiveIndex 的action
// eslint-disable-next-line no-undef
export const setActiveIndexCreator = (payload) => ({ type: CHANNEL_SET_INDEX, payload });
